//------------------------------------------------------------------------------------
//
//	This file defines the file format of the asset file
//
//------------------------------------------------------------------------------------

#ifndef ASSETFILE_HPP
#define ASSETFILE_HPP
#pragma pack(push,1)

#include "../hash/hash.h"

//------------------------------------------------------------------------------------
//	different block types
//	this corresponds to the type of memory it must go in
//------------------------------------------------------------------------------------
const u32	BLOCKTYPE_NORMAL = 0;
const u32	BLOCKTYPE_TEMP   = 1;
const u32	BLOCKTYPE_VRAM   = 2;

//------------------------------------------------------------------------------------
//	Locator ID for a chunk
//------------------------------------------------------------------------------------
typedef union
{
	struct
	{
		u16		blockId;
		u16		chunkId;
	};
	u32		id;
	void	*pData;

} LOCID;

//------------------------------------------------------------------------------------
//	Index entry for a chunk inside a block
//------------------------------------------------------------------------------------
class CBlockIndexEntry
{
public:
	HASH			nameHash;
	LOCID			locatorId;
	u32				blockOffset;
	u32				dataLength;
};

//------------------------------------------------------------------------------------
//	Index for a block
//------------------------------------------------------------------------------------
class CBlockIndex
{
public:
	u32				blockType		: 16;
	u32				blockAlignment	: 16;
	u32				indexLength;
	u32				blockLength;
	u32				numItems;

//	BlockIndexItem	items[numItems];
};

//------------------------------------------------------------------------------------
//	Index entry for an asset inside the file
//------------------------------------------------------------------------------------
class CMasterIndexEntry
{
public:
	HASH				nameHash;
	HASH				typeHash;
	LOCID				primaryChunk;
	void				*ptr;
};

//------------------------------------------------------------------------------------
//	Master index entry for the file
//------------------------------------------------------------------------------------
class CMasterIndex
{
public:
	u32					indexLength;			// length of master index
	u32					totalBlockIndexLength;	// length of all block indices
	u32					dictionaryLength;		// length of dictionary
	u32					numBlocks;				// number of blocks
	u32					numItems;				// number of items
//	CMasterIndexEntry	items[numItems];
};

//------------------------------------------------------------------------------------
//	file format:
//		CMasterIndex
//		CMasterIndexEntry[]
//		{
//			CBlockIndex
//			CBlockIndexEntry[]
//		} Blocks[]
//		BlockData[]
//		{
//			CStaticHashList	// dictionary
//			CHashListItem[]	// dictionary index
//			char[]			// words
//		} Dictionary
//------------------------------------------------------------------------------------

#pragma pack(pop)
#endif
